package com.hiv.controller.admin;

import com.hiv.common.BaseController;
import com.hiv.common.WebResponse;
import com.hiv.mapper.domain.Admin;
import com.hiv.mapper.domain.InspectionOfficeConfig;
import com.hiv.service.InspectionOfficeConfigService;
import com.hiv.utils.FileUploadUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
/**
 * @author zhanghong
 * @version AdminInspectionOfficeConfigController.java, v 0.1 2023-04-10 AdminInspectionOfficeConfigController Exp $$
 */
@RestController
@RequestMapping("/admin/inspectionOfficeConfig")
@Api(value = "检验所配置模块", tags = {"【管理端】检验所配置模块"})
public class AdminInspectionOfficeConfigController extends BaseController {
    @Autowired
    private InspectionOfficeConfigService inspectionOfficeConfigService;

    @ApiOperation(value = "根据id查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get")
    public WebResponse<InspectionOfficeConfig> getById(HttpServletRequest request) {
        Admin admin = validAdminLoginAndGet(request);
        return WebResponse.build(inspectionOfficeConfigService.getById(admin));
    }

    @ApiOperation(value = "保存", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/save")
    public WebResponse<Boolean> save(HttpServletRequest request, @RequestBody InspectionOfficeConfig param) {
        Admin admin = validAdminLoginAndGet(request);
        return WebResponse.build(inspectionOfficeConfigService.save(admin, param));
    }

    @ApiOperation(value = "上传logo/电子章", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/upload")
    public WebResponse<String> uploadSignImage(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws Exception {
        return new WebResponse<>(FileUploadUtils.upload("/inspectionConfig", file));
    }
}
